home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / bipl.zip / PROCS.ZIP / INBITS.ICN < prev    next >
Text File  |  1992-11-20  |  1KB  |  55 lines

  1. ############################################################################
  2. #
  3. #    File:     inbits.icn
  4. #
  5. #    Subject:  Procedure to read variable-length characters
  6. #
  7. #    Author:   Richard L. Goerwitz
  8. #
  9. #    Date:     November 3, 1991
  10. #
  11. ###########################################################################
  12. #
  13. #    Version:  1.2
  14. #
  15. ###########################################################################
  16. #  
  17. #  This procedure, inbits(), re-imports data converted into writable
  18. #  form by outbits().  See the file outbits.icn for all the whys and
  19. #  hows.
  20. #
  21. ############################################################################
  22. #
  23. #  See also: outbits.icn
  24. #
  25. ############################################################################
  26.  
  27. procedure inbits(f, len)
  28.  
  29.     local i, byte, old_byte_mask
  30.     static old_byte, old_len, byte_length
  31.     initial {
  32.     old_byte := old_len := 0
  33.     byte_length := 8
  34.     }
  35.  
  36.     old_byte_mask := (0 < 2^old_len - 1) | 0
  37.     old_byte := iand(old_byte, old_byte_mask)
  38.     i := ishift(old_byte, len-old_len)
  39.  
  40.     len -:= (len > old_len) | {
  41.     old_len -:= len
  42.     return i
  43.     }
  44.     
  45.     while byte := ord(reads(f)) do {
  46.     i := ior(i, ishift(byte, len-byte_length))
  47.     len -:= (len > byte_length) | {
  48.         old_len := byte_length-len
  49.         old_byte := byte
  50.         return i
  51.     }
  52.     }
  53.  
  54. end
  55.